﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraEditors;

namespace TMIS
{
    public partial class frmSummary : frmCommon
    {
        private BLL.Summary bll = new BLL.Summary();
        public frmSummary()
        {
            InitializeComponent();
            this.FillComponent();
        }
        private void FillComponent()
        {
            comDepartment.Properties.Items.AddRange(bll.GetDepartment());
        }
        private void frmSummary_Load(object sender, EventArgs e)
        {
        }
        public override void Save()
        {
            Model.Summary summary = new Model.Summary()
            {
                ID = bll.GetGradeID(comGrade.Text),
                Decription = txtSummary.Text
            };
            if (bll.Check(comGrade.Text))
            {
                bll.Update(bll.GetGradeID(comGrade.Text), summary);
            }
            else
            {
                bll.Add(summary);
            }
        }
        public override void Priview()
        {
            this.summaryTableAdapter.FillByGradeID(this.reportDS.Summary, bll.GetGradeID(comGrade.Text));
            this.reportViewer1.RefreshReport();
        }

        private void comDepartment_SelectedValueChanged(object sender, EventArgs e)
        {
            comProfession.Properties.Items.Clear();
            comProfession.Properties.Items.AddRange(bll.GetProfession(bll.GetDepartmentID(comDepartment.Text)));
        }

        private void comProfession_SelectedValueChanged(object sender, EventArgs e)
        {
            comGrade.Properties.Items.Clear();
            comGrade.Properties.Items.AddRange(bll.GetGrade(bll.GetProfessionID(comProfession.Text)));
        }

        private void comGrade_SelectedValueChanged(object sender, EventArgs e)
        {
            if (bll.Check(comGrade.Text))
            {
                Model.Summary summary = bll.GetSummary(bll.GetGradeID(comGrade.Text));
                txtSummary.Text = summary.Decription;
            }
            else
            {
                txtSummary.Text = "";
            }

            this.Priview();
        }
    }
}
